package com.ctrip.ec.biz.dao.member;
import com.ctrip.ec.biz.entity.member.MemberViewEntityEx;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.member.MemberViewEntity;
import com.ctrip.ec.dal.DbAccess;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

@Service
public class MemberViewDao extends DaoBase<MemberViewEntity> {
    public MemberViewDao() {
        super(MemberViewEntity.class);
    }
    public MemberViewDao(DbAccess db) {
        super(MemberViewEntity.class,db);
    }

    public List<MemberViewEntityEx> list(String from, String to, Integer viewType) throws SQLException {

        String sql = "select count(*) as visit_count,current_year,current_month,current_day from " + this.getTableName() +
                     " where add_time>='" + from + "' and add_time<='" + to + "' ";
        if(viewType != null){
            sql += " and view_type=" + viewType;
        }
        sql += " group by current_year,current_month,current_day";

        List<MemberViewEntityEx>  list = this.db.query(MemberViewEntityEx.class,sql);
        return list;
    }
}
